package sdc.com.petscalendar.fragments;

import sdc.com.petscalendar.R;
import sdc.com.petscalendar.objects.Parasite;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class ParasiteDetailFragment extends BaseFragment implements
		View.OnClickListener {
	private ImageView mIvParasiteAvatar;
	private TextView mTvParasiteName, mTvParasiteDescription;
	private Button mBtnTreatment, mBtnReturn;
	private Parasite mParasite;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (mView == null) {
			mView = inflater.inflate(R.layout.fragment_parasite_details,
					container, false);
		}
		return mView;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		initComponents();
		addListeners();
	}

	private void initComponents() {
		mTvParasiteName = (TextView) getView().findViewById(
				R.id.tv_parasite_name);
		mTvParasiteDescription = (TextView) getView().findViewById(
				R.id.tv_parasite_description);

		mIvParasiteAvatar = (ImageView) getView().findViewById(
				R.id.iv_parasite_avatar);
		mBtnReturn = (Button) getView().findViewById(R.id.btn_return);
		mBtnTreatment = (Button) getView().findViewById(R.id.btn_treament);

		if (mParasite != null) {
			mTvParasiteDescription.setText(mParasite.getDescription());
			mTvParasiteName.setText(mParasite.getName());
			if (mParasite.getAvatar() != null
					&& mParasite.getAvatar().length() > 0) {
				Bitmap bm = BitmapFactory.decodeFile(mParasite.getAvatar());
				mIvParasiteAvatar.setImageBitmap(bm);
			}
		}
	}

	private void addListeners() {
		mBtnReturn.setOnClickListener(this);
		mBtnTreatment.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_return:
			getActivity().onBackPressed();
			break;
		case R.id.btn_treament:

			break;
		default:
			break;
		}

	}

	public void setParasite(Parasite parasite) {
		mParasite = parasite;
	}
}
